package com.qing.study;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 表示SpringBoot项目的启动类
 */
//该注解标注当前类是SpringBoot的启动类
@SpringBootApplication
//标注启动swagger接口文档
@EnableSwaggerBootstrapUI
@MapperScan(basePackages = "com.qing.study.mapper")
@EnableScheduling
//启用异步任务
@EnableAsync
@Slf4j
public class QingApplication {
    //SpringBoot启动入口方法
    public static void main(String[] args) throws UnknownHostException {
        //加载当前启动类
        ConfigurableApplicationContext application = SpringApplication.run(QingApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        log.info("\n----------------------------------------------------------\n\t" +
                "Application is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "\n\t" +
                "Swagger文档: \thttp://" + ip + ":" + port + path + "doc.html\n" +
                "----------------------------------------------------------");
    }

}
